package com.example.demo.executor.backupDeal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class BackupDataExecutorFactory {

    @Autowired
    List<BackupDataExecutor> backupDataExecutorList;

    Map<String,BackupDataExecutor> backupDataExecutorMap;

    @PostConstruct
    public void init(){
        backupDataExecutorMap = new HashMap<>();
        for(BackupDataExecutor executor : backupDataExecutorList){
            backupDataExecutorMap.put(executor.getDealStrategy(), executor);
        }
    }

    public BackupDataExecutor getBackupDataExecutor(String dealStrategy){
        return backupDataExecutorMap.get(dealStrategy);
    }
}
